package com.woniuxy.infrastructure.controller;

import com.woniuxy.infrastructure.pojo.MeterReading;
import com.woniuxy.infrastructure.service.MeterReadingService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;
import java.util.HashMap;

@RestController
@RequestMapping("/meter-reading")
public class MeterReadingController {

    @Autowired
    private MeterReadingService meterReadingService;

    @PostMapping("/query")
    public List<MeterReading> query(@RequestBody MeterReading meterReading) {
        return meterReadingService.query(meterReading);
    }

    @GetMapping("/all")
    public List<MeterReading> queryAll() {
        return meterReadingService.queryAll();
    }

    @PostMapping("/add")
    public Map<String, Object> add(@RequestBody MeterReading meterReading) {
        Map<String, Object> result = new HashMap<>();
        boolean success = meterReadingService.addMeterReading(meterReading);
        result.put("success", success);
        result.put("message", success ? "抄表记录添加成功" : "抄表记录添加失败");
        return result;
    }

    @GetMapping("/pay")
    public String pay(){
        return meterReadingService.pay();
    }

    //未支付物业单
    @GetMapping("/payList")
    public List<MeterReading> payList(){
        return meterReadingService.payList();
    }
    //已支付物业单
    @GetMapping("/paidList")
    public List<MeterReading> paidList(){
        return meterReadingService.paidList();
    }
} 